﻿using System.Linq;
using UpperComputer.Core.Entities;
using YFurion.Application;
using YFurion.Application.EFCore.Extensions;
using YFurion.Extensions;

namespace UpperComputer.Application
{
    public class AuditLogService : EFCoreApplicationService<AuditLog, AuditLogDto, long, AuditLogResultRequestDto>, IAuditLogService
    {
        protected override IQueryable<AuditLog> CreateFilteredQuery(AuditLogResultRequestDto input)
        {
            IQueryable<AuditLog> queryable = base.CreateFilteredQuery(input)
                .WhereIf(!input.Account.IsNullOrWhiteSpace(), o => o.Account.StartsWith(input.Account))
                .WhereIf(input.StartTime != null, o => o.OperationTime >= input.StartTime)
                .WhereIf(input.EndTime != null, o => o.OperationTime <= input.EndTime);
            return queryable;
        }
    }
}
